import {
	getDateString
} from "@/assets/js/common.js";
let Controller = {
	mounted() {},
	activated() {
		this.requestTableList();
		// this.getDowmList();
	},
	methods: {
		onTableExport() {
			const arr = this.Model.selectionList;
			if (arr.length == 0) {
				this.$message.warning('请勾选需要导出的数据！')
				return;
			};
			const param = {
				name: 'purchaseStorage',
				idList: arr
			};
			this.$ajax({
				method: 'post',
				url: this.apiTest + `/supplier/common/exportExcel`,
				data: param,
				responseType: 'arraybuffer'
			}).then(res => {
				const data = res.data;
				let blob = new Blob([res.data], {
					type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
				});
				let objectUrl = URL.createObjectURL(blob);
				window.open(objectUrl);
			})
			/* this.$ajax.post(this.apiTest + `/supplier/common/exportExcel`,param)
			  .then(res => {
			    const data = res.data;
			    if(data.status == 200){
			      this.downloadExcel();
			    }
			  }).catch(err => {
			    this.$message.error('导出失败!')
			  }) */
		},
		getDowmList() {
			/* mock数据start */
			this.Model.filterOption.items = [
				{
					label: "颜色",
					type: "dropdown",
					data: [
						{
							label:'D',
							value:'D'
						},
						{
							label:'E',
							value:'E'
						},
						{
							label:'F',
							value:'F'
						},
						{
							label:'G',
							value:'G'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "inventoryLocation"
				},
				{
					label: "手寸",
					type: "dropdown",
					data: [
						{
							label:'10',
							value:'10'
						},
						{
							label:'12',
							value:'12'
						},
						{
							label:'15',
							value:'15'
						},
						{
							label:'17',
							value:'17'
						},
						{
							label:'18',
							value:'18'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "inventoryStatus"
				},
				{
					label: "钻重",
					type: "dropdown",
					data: [
						{
							label:'10',
							value:'10'
						},
						{
							label:'20',
							value:'20'
						},
						{
							label:'30',
							value:'30'
						},
						{
							label:'40',
							value:'40'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "createBy"
				},
				{
					label: "净度",
					type: "dropdown",
					data: [
						{
							label:'VG',
							value:'VG'
						},
						{
							label:'EX',
							value:'EX'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "submitter"
				},
				{
					label: "对称",
					type: "dropdown",
					data: [
						{
							label:'VG',
							value:'VG'
						},
						{
							label:'EX',
							value:'EX'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "submitter"
				},
				{
					label: "抛光",
					type: "dropdown",
					data: [
						{
							label:'VG',
							value:'VG'
						},
						{
							label:'EX',
							value:'EX'
						},
						{
							label:'STO',
							value:'STO'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "submitter"
				},
				{
					label: "荧光",
					type: "dropdown",
					data: [
						{
							label:'VG',
							value:'VG'
						},
						{
							label:'EX',
							value:'EX'
						},
						{
							label:'STO',
							value:'STO'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "submitter"
				},
				{
					label: "切工",
					type: "dropdown",
					data: [
						{
							label:'VG',
							value:'VG'
						},
						{
							label:'EX',
							value:'EX'
						},
					],
					placeholder: "请选择",
					value: undefined,
					key: "submitter"
				},
			];
			/* mock数据end */

			/* this.$ajax.post(this.apiTest + `/supplier/whWarehouse/getDropBox/204`, {})
				.then(res => {
					const data = res.data;
					if (data.status == 200) {
						const result = data.result;
						this.Model.filterOptionData = result;
						let locationArr = [],
							wareHouseStatusArr = [],
							wareHouseTypeArr = [],
							supplierArr = [];
						for (let i in result.location) { //入库仓库
							locationArr.push({
								label: result.location[i],
								value: i
							});
						};
						for (let i in result.wareHouseStatus) { //入库单状态
							wareHouseStatusArr.push({
								label: result.wareHouseStatus[i],
								value: i
							});
						};
						for (let i in result.wareHouseType) { //入库单类型
							wareHouseTypeArr.push({
								label: result.wareHouseType[i],
								value: i
							});
						};
						for (let i in result.supplier) { //入库单类型
							supplierArr.push({
								label: result.supplier[i],
								value: i
							});
						};
						this.Model.filterOption.items[4].data = supplierArr; //供应商
						this.Model.filterOption.items[3].data = locationArr; //入库仓库
						this.Model.filterOption.items[2].data = wareHouseStatusArr; //入库单状态
						this.Model.filterOption.items[1].data = wareHouseTypeArr; //入库单类型
						this.Model.defaultFilterOption = _.cloneDeep(this.Model.filterOption)
					}
				}) */
		},
		requestTableList() {
			//请求主表数据

			/* mock数据start */
			this.Model.tableData = [{
					originNumbe1r: '凯杰凯',
					countingNumber: '0494858',
					originNumber: '裸石',
					createBy: '0.30',
					location: '圆形',
					typeDict: '0.43',
					supplierName: 'D',
					createUser: 'EX',
					createTime: 'EX',
					updateUser: 'EX',
					sureTime: 'EX',
					remark: '白',
					remark1: '钻石鉴定',
					remark2: 248562,
					remark3: '件',
					remark4: '正常',
					remark5: 0,
				},
				{
					originNumbe1r: '宁神',
					countingNumber: '0494859',
					originNumber: '裸石',
					createBy: '0.35',
					location: '圆形',
					typeDict: '0.46',
					supplierName: 'C',
					createUser: 'EX',
					createTime: 'EX',
					updateUser: 'EX',
					sureTime: 'EX',
					remark: '白',
					remark1: '钻石鉴定',
					remark2: 248563,
					remark3: '件',
					remark4: '正常',
					remark5: 1,
				},
			];
			this.Model.pager.pageTotal = 5;
			this.Model.pager.pageIndex = 1;
			/* mock数据end */

			/* const params = {
				condition: {
					...this.getSearchInfoParam(),
					countType: 2,
					inventoryDirection: 1
				},
				...this.Model.pager.params,
			};
			this.$ajax
				.post(`/api/whInventoryMain/list`, params)
				.then(response => {
					const data = response.data;
					this.Model.tableData = data.result.result;
					this.Model.pager.pageTotal = data.result.total;
					this.Model.pager.pageIndex = data.result.pageIndex;
				})
				.catch(error => {
					this.$message.error('请求错误');
				}); */
		},
		getSearchInfoParam() {
			//编辑高级搜索时间格式
			let data = _.cloneDeep(this.Model.searchFromData);
			if (data.inventoryStart) {
				data.inventoryStartTime = getDateString(data.inventoryStart[0]);
				data.inventoryStartToTime = getDateString(data.inventoryStart[1]);
				data.inventoryStart = undefined;
			}
			if (data.inventoryEnd) {
				data.inventoryEndTime = getDateString(data.inventoryEnd[0]);
				data.inventoryEndToTime = getDateString(data.inventoryEnd[1]);
				data.inventoryEnd = undefined;
			}
			if (data.create) {
				data.createTime = getDateString(data.create[0]);
				data.createToTime = getDateString(data.create[1]);
				data.create = undefined;
			}
			if (data.submitInventory) {
				data.submitInventoryTime = getDateString(data.submitInventory[0]);
				data.submitInventoryToTime = getDateString(data.submitInventory[1]);
				data.submitInventory = undefined;
			}
			return data;
		},
		onTableSelectionChange(val) {
			//表格多选操作
			if (val.length == 0) {
				this.Model.selectionList = [];
				return;
			};
			let arr = val.map((item, index, list) => {
				return item.id
			});
			this.Model.selectionList = arr;
		},
		onTableCurrentChange(val) {
			//表格分页-当前页变动操作
			this.Model.pager.params.pageIndex = val;
			this.requestTableList();
		},
		onTableSizeChange(val) {
			//表格分页-页数量变动操作
			this.Model.pager.params.pageSize = val;
			this.requestTableList();
		},
		getFilterData(val, item, option) {
			for (let i = 0; i < 5; i++) {
				this.Model.filterOption.items[i] = option[i];
			}
			switch (item.key) {
				case 'saleOrderChannels':
					this.Model.filterOption.items[5].data = this.Model.saleManList[item.val].map(obj => {
						return {
							label: obj.value,
							value: obj.key
						}
					});
					this.Model.filterOption.items[5].value = undefined;
					break;
				case 'saleOrderTypes':
					this.Model.filterOption.items[3].data = this.Model.saleAfterOrderStatus[item.val].map(obj => {
						return {
							label: obj.value,
							value: obj.key
						}
					});
					this.Model.filterOption.items[3].value = undefined;
					break;
				default:
					break;
			};
			this.Model.searchFromData = val;
		},
		onFilterSearch(val) {
			this.requestTableList();
		},
		onFilterClear(val) {
			this.Model.searchFromData = _.cloneDeep(this.Model.defaultSearchFromData);
			this.Model.filterOption = _.cloneDeep(this.Model.defaultFilterOption);
		},
		onFilterExport(val) {},
		onTabChange(val) {
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		setPage(pageIndex, pageSize, pageTotal, total) {
			this.Model.pager.params = {
				pageIndex,
				pageSize
			};
			this.Model.pager.total = total;
		},
		cancelInSale(id) {
			this.$confirm('是否确认取消售中?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				this.$ajax
					.get(this.apiTest + `/sale/onSale/order/sale/cancel/${id}`)
					.then(response => {
						const data = response.data;
						if (data.status == 200 && data.result == 1) {
							this.$message({
								type: 'success',
								message: '已成功'
							});
							this.requestTableList();
						};
					})
					.catch(error => {
						this.$message.error('请求错误');
					});
			}).catch(() => {

			});

		},
		cancelRefund(id) {
			this.$confirm('是否确认取消退款?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				this.$ajax
					.get(this.apiTest + `/sale/onSale/order/refund/cancel/${id}`)
					.then(response => {
						const data = response.data;
						if (data.status == 200 && data.result == 1) {
							this.$message({
								type: 'success',
								message: '已成功'
							});
							this.requestTableList();
						};
					})
					.catch(error => {
						this.$message.error('请求错误');
					});
			}).catch(() => {

			});

		},
		sendlRefund(id) {
			this.$ajax
				.get(this.apiTest + `/sale/onSale/order/refund/Initiate/${id}`)
				.then(response => {
					const data = response.data;
					if (data.status == 200 && data.result == 1) {
						this.$message({
							type: 'success',
							message: '已成功'
						});
					}
				})
				.catch(error => {
					this.$message.error('请求错误');
				});
		},
		showPayDialog(id) {
			this.Model.dialogFormVisible = true;
			this.Model.nowSelectId = id;
		},
		pay() {
			const form = this.Model.dialogForm;
			const params = {
				payMethod: form.payMethod,
				paymentMoney: form.paymentMoney,
				serialNumber: form.serialNumber,
				payTime: getDateString(form.payTime),
				orderId: this.Model.nowSelectId
			};
			this.$ajax
				.post(this.apiTest + `/sale/onSale/order/afterSale/pay`, params)
				.then(response => {
					const data = response.data;
					if (data.status == 200) {
						this.$message({
							type: 'success',
							message: '已成功'
						});
						this.requestTableList();
					};
					this.Model.dialogFormVisible = false;
				})
				.catch(error => {
					this.$message.error('请求错误');
					this.Model.dialogFormVisible = false;
				});
		},
	}
}
export default Controller;
